# -----------------------------------------------
# Author: yuz
# Copyright: 湖南零檬信息技术有限公司
# Email: wagyu2016@163.com
# Phone&Wechat: 18173179913
# Site: http://www.lemonban.com
# Forum: http://testingpai.com
# -----------------------------------------------
import json

import requests

def adminLogin(username, password):
    """登录"""
    resp = requests.request(
        'POST',
        # url=Config.urls.adminLogin,
        url="http://mall.lemonban.com:8108/adminLogin",
        headers={"content-type": "application/json"},
        json={
            "principal": "student",
            "credentials": "123456a",
            "imageCode": "lemon"
        }
    )
    try:
        content = resp.json()
    except:
        raise ValueError(f"响应结果不是json:", resp.text)
    return content["access_token"]


def upload_img(url, file_path, token):
    """发送请求，上传文件"""
    headers = {"Authorization": f"bearer{token}"}
    files = {"file": open(file_path, "rb")}
    response = requests.post(url, files=files, headers=headers)
    return response.text


def upload_project(projectInfo, token):
    """"""
    headers = {"Authorization": f"bearer{token}"}
    # files = {"file": open(file_path, "rb")}
    url = 'http://mall.lemonban.com:8108/prod/prod'
    response = requests.post(url, json=projectInfo, headers=headers)
    return response.text




token = adminLogin('student', '123456a')
# a = upload_img("http://mall.lemonban.com:8108/admin/file/upload/img", "code.png", token)
a = upload_project('', token)
print(a)